package org.one.afternoon.config;

import com.alibaba.druid.pool.DruidDataSource;
import com.baomidou.dynamic.datasource.annotation.DS;
import org.apache.commons.dbcp.BasicDataSource;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.quartz.QuartzDataSource;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

/**
 * Druid连接池配置类
 */
@Configuration
public class DruidDataSourceConfig {

    private static final String BUSINESS_DATASOURCE_PREFIX = "spring.datasource";

    /**
     * 添加 DruidData Source 组件到容器中，并绑定属性
     */
    @Bean
    @Primary
    @ConfigurationProperties(prefix = BUSINESS_DATASOURCE_PREFIX)
    @ConditionalOnProperty(name = "spring.datasource.type", havingValue = "com.alibaba.druid.pool.DruidDataSource")
    public DataSource druid(){
        return  new DruidDataSource();
    }


//    /**
//     * @QuartzDataSource 注解则是配置Quartz独立数据源的配置
//     */
//    @Bean
//    @QuartzDataSource
//    @ConfigurationProperties(prefix = "spring.quartz.datasource")
//    @ConditionalOnProperty(name = "spring.datasource.type", havingValue = "com.alibaba.druid.pool.DruidDataSource")
//    public DataSource quartzDataSource(){
//       return new DruidDataSource();
//    }

}